home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / util / Mac F2C 1.3.sit / Mac F2C 1.3 / Mac F2C v1.3 Documentation.rsrc / TEXT_142.txt < prev    next >
Text File  |  1995-12-11  |  2KB  |  10 lines

  1. If Floating Point Numbers Don‚Äôt Display Right
  2.  
  3.  
  4. Many compilers (and/or their included support libraries) have trouble correctly rounding floating point values when converting them to ASCII representations (e.g., when printing them out using printf() or other standard I/O or stream I/O functions).  Unfortunately, Symantec‚Äôs C and C++ compilers for the Macintosh and MetroWerk‚Äôs CodeWarrior compilers fall into this category.  For example, if use Symantec‚Äôs THINK C and enter 1.21 as the single precision floating point value in the test program provided, the number that displays back is 1.21000004 instead of 1.21.  This is not due to any error in Mac F2C or in the Mac F2C support libraries.  The problem arises because the printf() function in Symantec‚Äôs ANSI library is inaccurate.  Note that Symantec‚Äôs compilers appear to have trouble only with single precision values.  Symantec‚Äôs printf() family of functions appears to handle double precision values correctly.   
  5.  
  6. Note that in every case the internal value used in computation is correct (as you can verify using the debugger).  However, if you have access to your compiler‚Äôs ANSI library source code, you can correct this problem.  The folder Fixing Floating Point Output (found in the Mac F2C Extras folder) contains two files (dtoa.c and g_fmt.c) that have the code you need to correctly display floating point values.
  7.  
  8. The functions in these two files replace the strtod() and dtoa() functions in the ANSI library supplied by your compiler vendor.  For 68K Macintoshes, be sure to #define IEEE_MC68k.  I don‚Äôt know enough about the PowerPC to provide guidance in that case.
  9.  
  10. These two files were written by David M. Gay and are Copyright ¬©1991 by AT&T.  AT&T gives permission to use, copy, modify, and distribute this software for any purpose without fee, provided that this entire notice is included in all copies of any software which is or includes a copy or modification of this software and in all copies of the supporting documentation for such software.  See the individual files for more detailed information and license restrictions.